<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="json"></div>
  <script>
    function preorderTraversal(root) {
      if (root == null) { return [] };
      const result = [];
      preorder(root, result);
      return result;

      function preorder(root, result) {
          if (root == null) return;
          result.push(root.val);
          preorder(root.left, result);
          preorder(root.right, result);
      }
    }

    console.log(preorderTraversal([1, null ,2 ,3]))

  </script>
</body>
</html>